<template>
	<view class="content">
		<u-tabs 
		bar-width="80"
		bg-color="transparent"
		inactive-color="rgba(94, 106, 252,0.8)"
		active-color="#ffffff" 
		:list="list" 
		:is-scroll="false" 
		:current="current"
		:show-bar="false"
		 @change="change"></u-tabs>
		<view class="tag" v-if="current !=2">
		 	<u-tabs 
		 	height="60"
		 	:active-item-style='active' 
		 	bg-color="transparent" 
		 	:list="listCard" 
		 	bar-width="50%" 
		 	inactive-color="rgba(94, 106, 252,0.8)"
		 	active-color="#ffffff" 
		 	:is-scroll="false" 
		 	:current="currentCard" 
		 	@change="changeCard"></u-tabs>
		</view>
		<view class="cont" v-show="current ==0">
		 	<view class="item" v-for="item in dataList" :key="item.id">
		 		<view class="top">
		 			<view class="lf">{{item.remark}}</view>
		 			<view class="lr">-{{item.dznumber}}</view>
		 		</view>
		 		<view class="btm">
		 			<view class="lf">{{item.create_time}}</view>
		 			<view class="lr">{{currentCard==0?'USDT':'BST'}}</view>
		 		</view>
		 	</view>
			<view class="msg" :class="{order_null:dataList.length<=0}">
				<u-empty v-if="dataList.length<=0" text="暂无转账数据" mode="list"></u-empty>
				<u-loadmore :status="status" />
			</view>
		</view>
		<view class="cont" v-show="current ==1">
		 	<view class="item" v-for="item in dataList" :key="item.id">
		 		<view class="top">
		 			<view class="lf">{{item.remark}}</view>
		 			<view class="lr">+{{item.number}}</view>
		 		</view>
		 		<view class="btm">
		 			<view class="lf">{{item.create_time}}</view>
		 			<view class="lr">{{currentCard==0?'USDT':'BST'}}</view>
		 		</view>
		 	</view>
			<view class="msg" :class="{order_null:dataList.length<=0}">
				<u-empty v-if="dataList.length<=0" text="暂无收款数据" mode="list"></u-empty>
				<u-loadmore :status="status" />
			</view>
		</view>
		<view class="cont" v-show="current ==2">
		 	<view class="item" v-for="item in dataList" :key="item.id">
		 		<view class="top">
		 			<view class="lf">{{item.reason}}</view>
		 			<view class="lr">+{{item.number}}</view>
		 		</view>
		 		<view class="btm">
		 			<view class="lf">{{item.create_time}}</view>
		 			<view class="lr">BST<!-- {{currentCard==0?'USDT':'BST'}} --></view>
		 		</view>
		 	</view>
			<view class="msg" :class="{order_null:dataList.length<=0}">
				<u-empty v-if="dataList.length<=0" text="暂无释放数据" mode="list"></u-empty>
				<u-loadmore :status="status" />
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				active: {
					border: '1px solid #5e6afc',
					backgroundColor:'#5e6afc',
					borderRadius: '12rpx'
				},
				list: [
					{name: '转账'}, 
					{name: '收款'}, 
					{name: '释放'},
				],
				current: 0,
				listCard: [
					{name: 'USDT'}, 
					{name: 'BST'},
				],
				currentCard:0,
				page:1,//当前页码
				list_rows:15,//每页数量
				total:0,//数据总量
				status: 'loadmore',
				dataList:[],
			}
		},
		onReady() {

		},
		onLoad() {
			this.get_withdraw()
		},
		onPullDownRefresh(){
			this.page = 1
			this.dataList = []
			if(this.current == 0){
				//转账
				this.get_withdraw()
			}
			if(this.current == 1){
				//收款
				this.get_recharge()
			}
			if(this.current == 2){
				//释放
				this.get_shifang()
			}
		},
		onReachBottom(){
			if(Math.ceil(this.total/this.list_rows)>this.page){
				this.page = this.page+1
				if(this.current == 0){
					this.get_withdraw()
				}
				if(this.current == 1){
					this.get_recharge()
				}
				if(this.current == 2){
					this.get_shifang()
				}
			}else{
				
			}
		},
		methods: {
			//释放
			get_shifang(){
				this.status = 'loading'
				this.$http({
					url:this.$api.user_shifang,
					method:'POST',
					hideLoading:false,
					data:{page:this.page,list_rows:this.list_rows,reason:'矿机释放获得'},
					success:res=>{
						this.total = res.data.total
						if(Math.ceil(this.total/this.list_rows)<=this.page){
							this.status = 'nomore'
							
						}else{
							this.status = 'loadmore'
						}
						this.dataList = this.dataList.concat(res.data.data)
					},
					fail:err=>{
						this.status = 'nomore'
						//console.log('失败返回------',err)
					},
					complete:e=>{
						uni.stopPullDownRefresh();
						if(!e.code){
							this.status = 'nomore'
						}
					}
				})
			},
			//收款记录
			get_recharge(){
				this.status = 'loading'
				this.$http({
					url:this.$api.recharge_getAll,
					method:'POST',
					hideLoading:false,
					data:{page:this.page,list_rows:this.list_rows,bid:this.currentCard+1},
					success:res=>{
						this.total = res.data.total
						if(Math.ceil(this.total/this.list_rows)<=this.page){
							this.status = 'nomore'
							
						}else{
							this.status = 'loadmore'
						}
						this.dataList = this.dataList.concat(res.data.data)
					},
					fail:err=>{
						this.status = 'nomore'
						//console.log('失败返回------',err)
					},
					complete:e=>{
						uni.stopPullDownRefresh();
						if(!e.code){
							this.status = 'nomore'
						}
					}
				})
			},
			//转账记录
			get_withdraw(){
				this.status = 'loading'
				this.$http({
					url:this.$api.withdraw_getAll,
					method:'POST',
					hideLoading:false,
					data:{page:this.page,list_rows:this.list_rows,bid:this.currentCard+1},
					success:res=>{
						this.total = res.data.total
						if(Math.ceil(this.total/this.list_rows)<=this.page){
							this.status = 'nomore'
							
						}else{
							this.status = 'loadmore'
						}
						this.dataList = this.dataList.concat(res.data.data)
					},
					fail:err=>{
						this.status = 'nomore'
						//console.log('失败返回------',err)
					},
					complete:e=>{
						uni.stopPullDownRefresh();
						if(!e.code){
							this.status = 'nomore'
						}
					}
				})
			},
			//切换tabs
			change(index) {
				this.current = index;
				this.dataList = []
				this.page = 1
				if(index == 0){
					this.get_withdraw()
				}
				if(index == 1){
					this.get_recharge()
				}
				if(index == 2){
					this.get_shifang()
				}
			},
			//切换二级tabs
			changeCard(index){
				this.dataList = []
				this.page = 1
				this.currentCard = index
				if(this.current == 0){
					this.get_withdraw()
				}
				if(this.current == 1){
					this.get_recharge()
				}
				
			}
		}
	}
</script>
<style lang="scss" scoped>
	.content{
		.tag {
			margin: 22rpx 40rpx 0 40rpx;
			border: 1px solid rgba(94, 106, 252,0.5);
			border-radius: 15rpx;
		}
		.cont{
			margin: 16rpx 26rpx 0 26rpx;
			.item{
				padding: 22rpx 10rpx;
				border-bottom: 1px solid $border-bottom-color;
				>view{
					display: flex;
					justify-content: space-between;
				}
				.top{
					font-size:14px;
					font-weight: 600;
					color: #FFFFFF;
					letter-spacing: 1px;
				}
				.btm{
					font-size: 12px;
					color: #626cff;
					margin-top: 10rpx;
				}
			}
			.item:last-child{
				border-bottom: 0;
			}
		}
		.msg{
			padding: 20rpx;
		}
		.order_null{
			position: fixed;
			left: 0%;
			top: 50%;
			width: 100%;
		}
	}
</style>
